<template>
    <div class="work_wrap" style="top:0">
        <header >
            <span>工作台</span>
            <span @click="changeStudent" v-if="useInfo.userTypeId==4" class="add">切换</span>
        </header>
      <workbench :workData=workData :useInfo=useInfo ></workbench>
      <workbench :workData=workData2 :useInfo=useInfo style="margin:0.2rem 0"></workbench>
      <workbench v-if="useInfo.userTypeId!=4" style="margin-bottom:0.2rem;" :workData=workData3 :useInfo=useInfo ></workbench>
      <workbench :workData=workData4 :useInfo=useInfo ></workbench>
      <mt-actionsheet
        :closeOnClickModal=true
        cancelText=''
        :actions="actions"
        v-model="sheetVisible">
      </mt-actionsheet>
        <!-- <mt-actionsheet
        :closeOnClickModal=true
        position="center"
        cancelText=''
        :actions="actions2"
        v-model="sheetVisible2">
        </mt-actionsheet> -->
        <mt-popup
  v-model="sheetVisible2"
  :closeOnClickModal=false
   class="select_class popup_center"
  popup-transition="popup-fade">
   <div class="main" v-for="(item,index) in useInfo.studentList">
        <div class="flex" @click="selectStudent(item,index)">
            <div class="head" >
                <img  :src="$api.formatterImg(item.studentPhoto)" />
            </div>
            <div class="classroom" @click="selectStudent(item,index)">
                <div class="className">{{item.studentName}}</div>
            </div>
        </div>     
    </div>
    </mt-popup>
    </div>
  </template>
<script>
    import checkbox from '../components/checkbox'
    import {
        MessageBox
    } from 'mint-ui';
    export default {
        data() {
            return {
                // title: '信息管理',
                useInfo: {},
                workData: {
                    title: '信息管理',
                    title2: '校园信息',
                    child: [{
                        text: '校区管理',
                        text2: '校区简介',
                        href: '/g11',
                        voOperate: this.getOperate(0),
                        imgSrc: require('../../static/images/gzt/01@2x.png'),
                        parameter: '测试参数'
                    }, {
                        text: '班级管理',
                        text2: '我的班级',
                        href: '/g12',
                        voOperate: this.getOperate(1),
                        fun: this.classManage,
                        imgSrc: require('../../static/images/gzt/02@2x.png')
                    }, {
                        text: '教师管理',
                        text2: '我的教师',
                        href: '/g13',
                        voOperate: this.getOperate(2),
                        imgSrc: require('../../static/images/gzt/03@2x.png')
                    }, {
                        text: '学生管理',
                        href: '/g14',
                        voOperate: this.getOperate(3),
                        imgSrc: require('../../static/images/gzt/04@2x.png')
                    }, {
                        text: '课程管理',
                        text2: '课程简介',
                        href: '/g15',
                        voOperate: this.getOperate(4),
                        imgSrc: require('../../static/images/gzt/05@2x.png')
                    }, {
                        text: '缴费提醒',
                        href: '/g16',
                        hide: false,
                        voOperate: this.getOperate(5),
                        imgSrc: require('../../static/images/gzt/06@2x.png')
                    }, {
                        text: '健康管理',
                        href: '/g17',
                        hide: this.hideForParent(),
                        voOperate: this.getOperate(6),
                        imgSrc: require('../../static/images/gzt/07@2x.png')
                    }, {
                        text: '食谱记录',
                        href: '/g24',
                        hide: this.hideForMaster(),
                        voOperate: this.getOperate(10),
                        imgSrc: require('../../static/images/gzt/11@2x.png')
                    }, ]
                },
                workData2: {
                    title: '日常管理',
                    title2: '在校信息',
                    child: [{
                        text: '午托点名',
                        href: '/g21',
                        voOperate: this.getOperate(7),
                        fun: this.wutuodianming,
                        imgSrc: require('../../static/images/gzt/08@2x.png')
                    }, {
                        text: '晚托点名',
                        href: '/g22',
                        fun: this.wantuodianming,
                        voOperate: this.getOperate(8),
                        imgSrc: require('../../static/images/gzt/09@2x.png')
                    }, {
                        text: '课程点名',
                        href: '/g23',
                        fun: this.kechengdianming,
                        voOperate: this.getOperate(9),
                        imgSrc: require('../../static/images/gzt/10@2x.png')
                    }, {
                        text: '食谱记录',
                        href: '/g24',
                        hide: this.hideForParent(),
                        voOperate: this.getOperate(10),
                        imgSrc: require('../../static/images/gzt/11@2x.png')
                    }, {
                        text: '作业点评',
                        href: '/g25',
                        fun: this.zuoyedianping,
                        voOperate: this.getOperate(11),
                        imgSrc: require('../../static/images/gzt/12@2x.png')
                    }, {
                        text: '试卷点评',
                        href: '/g26',
                        fun: this.shijuandianping,
                        voOperate: this.getOperate(12),
                        imgSrc: require('../../static/images/gzt/13@2x.png')
                    }, {
                        text: '到校情况',
                        href: '/g31',
                        hide: this.hideForMaster(),
                        voOperate: this.getOperate(13),
                        imgSrc: require('../../static/images/gzt/14@2x.png')
                    }, {
                        text: '健康管理',
                        href: '/g28',
                        hide: this.hideForMaster(),
                        voOperate: this.getOperate(6),
                        imgSrc: require('../../static/images/gzt/07@2x.png')
                    }]
                },
                workData3: {
                    title: '统计分析',
                    child: [{
                        text: '到校情况',
                        // href: '/g31',
                        href: '/CommingSoon',
                        hide: this.hideForParent(),
                        voOperate: this.getOperate(13),
                        imgSrc: require('../../static/images/gzt/14@2x.png')
                    }, {
                        text: '学生表现',
                        //href: '/g32',
                        href: '/CommingSoon',
                        voOperate: this.getOperate(14),
                        imgSrc: require('../../static/images/gzt/15@2x.png')
                    }, ]
                },
                workData4: {
                    title: '综合管理',
                    title2: '综合信息',
                    child: [{
                        text: '安全定位',
                        //href: '/g41',
                        href: '/CommingSoon',
                        voOperate: this.getOperate(15),
                        imgSrc: require('../../static/images/gzt/16@2x.png')
                    }, {
                        text: '视频监控',
                        //href: '/g42',
                        href: '/CommingSoon',
                        voOperate: this.getOperate(16),
                        imgSrc: require('../../static/images/gzt/17@2x.png')
                    }, {
                        text: '积分管理',
                        //href: '/g43',
                        href: '/CommingSoon',
                        voOperate: this.getOperate(17),
                        imgSrc: require('../../static/images/gzt/18@2x.png')
                    }, {
                        text: '商城',
                        //href: '/g44',
                        href: '/CommingSoon',
                        voOperate: this.getOperate(18),
                        imgSrc: require('../../static/images/gzt/19@2x.png')
                    }]
                },
                actions: [{
                    name: '签到点名',
                    state: 0,
                    method: this.selectState
                }, {
                    name: '签退点名',
                    state: 1,
                    method: this.selectState
                }],
                actions2: [],
                studentList: [],
                sheetVisible: false,
                sheetVisible2: false, //控制切换学生底部弹窗显示
            }
        },
        components: {
            checkbox,
        },
        methods: {
            getOperate(index) {
                let useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
                return useInfo.tsMenuList[index].voOperate;
            },
            hideForParent() {
                let useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
                return (useInfo.userTypeId == 4);
            },
            hideForMaster() {
                let useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
                return (useInfo.userTypeId != 4);
            },
            getUserInfo() {
                this.useInfo = JSON.parse(sessionStorage.getItem('useInfo'));
                console.log(JSON.parse(JSON.stringify(this.useInfo)));
            },
            //点名相关
            wutuodianming() { //午托点名
                this.dianming('1');
            },
            wantuodianming() { //晚托点名
                this.dianming('2');
            },
            kechengdianming() { //课程点名
                this.dianming('4');
            },
            dianming(studentListType) {
                console.log(studentListType);
                this.sheetVisible = true;
                sessionStorage.setItem('studentListType', studentListType); //1午托,2晚托,3班级详情,4课程点名

            },
            changeStudent() {
                if (this.useInfo.studentList.length == 0) {
                    MessageBox('提示', '学生列表为空');
                    return;
                }
                var arr = this.useInfo.studentList.map((o, index) => {
                    o.name = o.studentName
                    o.method = this.selectStudent
                    return o;
                });
                this.useInfo.studentList = JSON.parse(JSON.stringify(arr));
                this.sheetVisible2 = true;
            },
            selectStudent(item, index) {
                // if (item.checked) {

                // }
                var array = this.useInfo.studentList.map(element => {
                    element.checked = false;
                    return element;
                });

                array[index].checked = true
                this.useInfo.studentList = JSON.parse(JSON.stringify(array));
                this.sheetVisible2 = false;
                console.log(JSON.parse(JSON.stringify(this.useInfo)));
                sessionStorage.setItem('useInfo', JSON.stringify(this.useInfo));

            },
            selectState(item) { //选择签到或签退,0为签到,1为签退
                sessionStorage.setItem('markType', item.state);
                this.$router.push({
                    path: 'g21'
                })
            }, //前面都是点名相关
            //接下来是点评相关
            zuoyedianping() { //作业点评
                if (this.useInfo.userTypeId == 4) {
                    this.$router.push({
                        path: 'g25'
                    });
                    return;
                }
                this.dianping(2);
            },
            shijuandianping() { //试卷点评
                if (this.useInfo.userTypeId == 4) {
                    this.$router.push({
                        path: 'g26'
                    });
                    return;
                }
                this.dianping(3);
            },
            dianping(dianpingType) { //跳转班级管理,存储数据告诉班级管理我只是选个班级而已
                var studentType = {
                    header: '全部学生',
                    type: dianpingType,
                }
                sessionStorage.setItem('studentType', JSON.stringify(studentType));
                this.$router.push({
                    path: 'g12'
                })
            },
            classManage() {
                var studentType = {
                    header: '全部学生',
                    type: 3,
                }
                this.$api.clearItem();
                this.$router.push({
                    path: 'g12'
                })
            }
        },
        created() {
            this.getUserInfo();
        }
    }
</script>
<style>
    .work_wrap {
        flex-direction: column;
        display: flex;
        /* justify-content: space-between; */
        flex-grow: 1
    }
    
    .workContainer {
        padding-bottom: 0.1rem;
    }
</style>